import request from '@/router/axios'
// import website from "@/config/website";
import { baseUrl } from './baseUrl'

export const loginByUsername = (username, password) =>
  request({
    url: baseUrl + '/users/login',
    method: 'post',
    data: {
      password,
      username
      // tenantId,
      // grantType: 'password',
      // userType: '1'
    }
  })

export const loginBySocial = (tenantId, source, code, state) =>
  request({
    url: '/api/blade-auth/oauth/token',
    method: 'post',
    headers: {
      'Tenant-Id': tenantId
    },
    params: {
      tenantId,
      source,
      code,
      state,
      grant_type: 'social',
      scope: 'all'
    }
  })

export const refreshToken = (refreshToken, tenantId, userType) =>
  request({
    url: baseUrl + 'system/login/token',
    method: 'post',
    data: {
      tenantId,
      userType,
      grantType: 'refresh_token'
    }
  })

export const registerGuest = (form, oauthId) =>
  request({
    url: '/api/blade-user/register-guest',
    method: 'post',
    params: {
      tenantId: form.tenantId,
      name: form.name,
      account: form.account,
      password: form.password,
      oauthId
    }
  })

export const getButtons = () =>
  request({
    url: baseUrl + 'system/menu/buttons',
    method: 'get'
  })

export const getCaptcha = () =>
  request({
    url: '/api/auth/oauth/captcha',
    method: 'get'
  })

export const logout = () =>
  request({
    url: baseUrl + 'system/login/logout',
    method: 'get'
  })

export const getUserInfo = () =>
  request({
    url: '/api/blade-auth/oauth/user-info',
    method: 'get'
  })

export const sendLogs = (list) =>
  request({
    url: '/api/blade-auth/oauth/logout',
    method: 'post',
    data: list
  })

export const clearCache = () =>
  request({
    url: baseUrl + 'system/login/clear-cache',
    method: 'get'
  })
